package com.alibaba.cola.statemachine;

/**
 * {@code Transition} is something what a state machine associates with a state
 * changes.
 * 状态机状态流转
 *
 * @param <S> the type of state
 * @param <E> the type of event
 * @param <C> the type of user defined context, which is used to hold application data
 * @author Frank Zhang
 * @date 2020-02-07 2:20 PM
 */
public interface Transition<S, E, C> {
    /**
     * Gets the source state of this transition.
     * 获取流转的原状态
     *
     * @return the source state 原状态
     */
    State<S, E, C> getSource();

    /**
     * Sets the source state of this transition.
     * 设置流转的原状态
     *
     * @param state the source state 原状态
     */
    void setSource(State<S, E, C> state);

    /**
     * Gets the event of this transition.
     * 获取流转的事件
     *
     * @return the event 事件
     */
    E getEvent();

    /**
     * Sets the event of this transition.
     * 设置流转的事件
     *
     * @param event the event 事件
     */
    void setEvent(E event);

    /**
     * Gets the type of this transition.
     * 获取流转的类型
     *
     * @param type the type of this transition 流转类型
     */
    void setType(TransitionType type);

    /**
     * Gets the target state of this transition.
     * 获取流转的目标状态
     *
     * @return the target state
     */
    State<S, E, C> getTarget();

    /**
     * Sets the target state of this transition.
     * 设置流转的目标状态
     *
     * @param state the target state 目标状态
     */
    void setTarget(State<S, E, C> state);

    /**
     * Gets the condition of this transition.
     * 获取流转的条件
     *
     * @return the condition 条件
     */
    Condition<C> getCondition();

    /**
     * Sets the condition of this transition.
     * 设置流转的条件
     *
     * @param condition the condition 条件
     */
    void setCondition(Condition<C> condition);

    /**
     * Gets the action of this transition.
     * 获取流转的动作
     *
     * @return the action 动作
     */
    Action<S, E, C> getAction();

    /**
     * Sets the action of this transition.
     * 设置流转的动作
     *
     * @param action the action 动作
     */
    void setAction(Action<S, E, C> action);

    /**
     * Do transition from source state to target state.
     * 从原状态流转到目标状态
     *
     * @param ctx            the context of this transition 流转上下文
     * @return the target state 目标状态
     */
    State<S, E, C> transit(C ctx);

    /**
     * Verify transition correctness
     * 验证流转的正确性
     */
    void verify();
}
